package com.caijin.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.caijin.common.core.domain.Result;
import com.caijin.common.core.domain.entity.Course;
import com.caijin.common.enums.ResultCode;
import com.caijin.system.mapper.CourseMapper;
import com.caijin.system.service.ICourseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.caijin.system.service.IStudentClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 课程表 服务实现类
 * </p>
 *
 * @author Peas
 * @since 2021-01-18
 */
@Service
@Transactional
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements ICourseService {

    @Autowired
    private CourseMapper mapper;

    /**
     * 创建课程
     *
     * @param course 课程信息
     * @return 结果
     */
    @Override
    public Result createCourse(Course course) {
        int insert = mapper.insert(course);
        return insert != 0 ? Result.ok().data("cno", course.getCno()) : Result.error();
    }

    /**
     * 根据教师工号获取课程列表
     *
     * @param tno 教师id
     * @return
     */
    @Override
    public Result getCourseListByTno(Long tno) {
        QueryWrapper<Course> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("tno", tno);
        List<Course> courses = this.mapper.selectList(queryWrapper);
        return courses != null ? Result.ok().data("courseList", courses) : Result.error();
    }

}
